//
//  ChatUser.swift
//  Employee
//
//  Created by swordjoy on 2017/3/14.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation
import SwiftyJSON

/// 通讯录列表
class ChatUser: NSObject, NSCoding {
  
  let id: String
  let nickname: String
  let phoneNumber: String
  let headIconUrl: String
  let department: String
  
  init(json: JSON) {
    
    self.id = json["staffId"].stringValue
    
    
    self.nickname = json["staffName"].stringValue
    self.phoneNumber = json["staffPhone"].stringValue
    self.headIconUrl = json["avatar"].stringValue
    self.department = json["orgName"].stringValue
    
  }
  
  static func array(from jsonArray: [JSON]) -> [ChatUser] {
    return jsonArray.map({ (json) -> ChatUser in
      ChatUser(json: json)
    })
  }
  
  required init?(coder aDecoder: NSCoder) {
    
    id = (aDecoder.decodeObject(forKey: "staffId") as? String) ?? ""
    nickname = (aDecoder.decodeObject(forKey: "staffName") as? String) ?? ""
    phoneNumber = (aDecoder.decodeObject(forKey: "staffPhone") as? String) ?? ""
    headIconUrl = (aDecoder.decodeObject(forKey: "avatar") as? String) ?? ""
    department = (aDecoder.decodeObject(forKey: "orgName") as? String) ?? ""
    
  }
  
  func encode(with aCoder: NSCoder) {
    
    aCoder.encode(id, forKey: "staffId")
    aCoder.encode(nickname, forKey: "staffName")
    aCoder.encode(phoneNumber, forKey: "staffPhone")
    aCoder.encode(headIconUrl, forKey: "avatar")
    aCoder.encode(department, forKey: "orgName")
    
  }
  
}
